package com.lcxw.hxzbapi.controller.appcontroller;

import com.alibaba.fastjson.JSONObject;
import com.lcxw.hxzbapi.entity.pojo.YwpdMember;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.YwpdMemberService;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
@Slf4j
public class CancelController {

    @Resource
    YwpdMemberService ywpdMemberService;

    @PostMapping("/cancel")
    public Response cancelUser(@RequestBody JSONObject requestBody) {
        long userId = Long.parseLong(requestBody.getString("userId"));
        YwpdMember ywpdMember = ywpdMemberService.selectYwpdMemberByUserId(userId);
        ywpdMember.setCancelled(1);
        try {
            ywpdMemberService.updateYwpdMember(ywpdMember);
        } catch (Exception e) {
            return Response.dbFail(log, "注销用户失败");
        }
        return Response.ok();
    }

}
